<? include block('htmla');

if (!function_exists('showSelectableStruct')) {
	function showSelectableStruct($_root, $levels, $current, $data, $rid) {

		foreach($_root as $id => $v) {
			
			$class = array("level$current", $v['first'], $v['last']);

			?><li class="<?=implode(' ', array_trim_empty($class))?>"><?
			
			?><label><input type="checkbox" name="r<?=$rid?>[]" value="<?=$id?>" <?=is_array($data) ? (in_array($id, $data) ? 'checked="checked"' : '') : 'checked="checked"' ?> /><?
				?><?=$v['name']?><?
			?></label><?
			
			if ($levels > $current)
				if (isset($v['data']) && sizeof($v['data'])) {
					?><ul class="level<?=$current + 1?>"><? showSelectableStruct($v['data'], $levels, $current + 1, $data, $rid); ?></ul><?
				}
	
			?></li><?
		}
		
	}
}

startScript('jquery'); ?><script type="text/javascript">
jQuery(function() {
	$(".page .detailed:not(:checked)").parent().next().show();
	$(".page .detailed").change(function(){
		if ($(this).attr("checked"))
			$(this).parent().next().hide();
		else
			$(this).parent().next().show();
	});
	$(".page .struct input").change(function(){
		$(this).parent().parent().find("input").attr("checked", $(this).attr("checked"));
	});
})
</script><? endScript(); ?>

<form action="" method="post" enctype="multipart/form-data">

<fieldset><legend> = </legend><?

		?><div><label>Имя пользователя <br />
			<input type="text" name="name" maxlength="200" class="xwide" value="<?=h($DATA['object']['name'])?>" />
		</label></div><?

		?><div><label>Логин <br />
			<input type="text" name="login" maxlength="200" class="xwide" value="<?=h($DATA['object']['login'])?>" />
		</label></div><?

		?><div><label>Новый пароль <br />
			<input type="password" name="pass" maxlength="200" class="xwide" />
		</label></div><?

		if (sizeof($d = dat('roles'))) {

			?><fieldset><legend> Роли </legend><?
			
				foreach($d as $id => $v) {
					?><label><?
						?><input type="checkbox" name="role[]" value="<?=$id?>" <?=$DATA['sess'][$id] ? 'checked="checked"' : ''?> /><?
						?><?=$v['name']?><?
					?></label><?
				}
				
			?></fieldset><?

		} else {
			?><p class="diags">Роли не определены.</p><?
		}
			
		?><p><input type="submit" name="editor_save" value="Сохранить" /></p><?

	?></fieldset><?

?></form><?

include block('_htmla');